package com.zisu.aradvertising.controller;



import com.zisu.aradvertising.pojo.Cooperation;
import com.zisu.aradvertising.pojo.Result;
import com.zisu.aradvertising.service.CooperationService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/cooperation")
public class CooperationController {
    @Resource
    private CooperationService cooperationService;
    //新增修改合作控制
    @PostMapping("/edit")
    public Result<Cooperation> editController(@RequestBody Cooperation newcooperation) {
        Cooperation cooperation1 = cooperationService.editCooperationService(newcooperation);
        if (cooperation1 != null) {
            return Result.success(cooperation1, "修改新增合作成功!");
        } else{
            return  Result.error("123","操作合作失败!");
        }
    }

    //取消合作控制
    @PostMapping("/cancel")
    public Result<Cooperation> cancelController(@RequestParam int coid){
        Cooperation cooperation2=cooperationService.cancelCooperationService(coid);
        if (cooperation2 != null) {
            return Result.success(cooperation2, "拒绝合作成功!");
        } else{
            return  Result.error("123","拒绝合作失败!");
        }
    }

    //同意合作
    @PostMapping("/agree")
    public Result<Cooperation> agreeController(@RequestParam int coid){
        Cooperation cooperation=cooperationService.agree(coid);
        if (cooperation != null) {
            return Result.success(cooperation, "同意合作成功!");
        } else{
            return  Result.error("123","同意合作失败!");
        }
    }

    //拒绝合作
    @PostMapping("/refuse")
    public Result<Cooperation> refuseController(@RequestParam int coid){
        Cooperation cooperation6=cooperationService.refuse(coid);
        if (cooperation6 != null) {
            return Result.success(cooperation6, "拒绝合作成功!");
        } else{
            return  Result.error("123","拒绝合作失败");
        }
    }

    //返回广告商所有的合作信息
    @PostMapping("/findallbyaid")
    public Result<List<Cooperation>> findAllbyaidController(@RequestParam int aid){
        List<Cooperation> cooperation3=cooperationService.findAllCoByAid(aid);
        if (cooperation3 != null) {
            return Result.success(cooperation3, "返回合作信息成功!");
        } else{
            return  Result.error("123","无历史订单");
        }
    }

    //返回视频创作者所有的合作信息
    @PostMapping("/findallbycid")
    public Result<List<Cooperation>> findAllbycidController(@RequestParam int cid){
        List<Cooperation> cooperation4=cooperationService.findAllCoByCid(cid);
        if (cooperation4 != null) {
            return Result.success(cooperation4, "返回合作信息成功!");
        } else{
            return  Result.error("123","无历史订单");
        }
    }
    //删除合作
    @PostMapping("/delete")
    public Result deleteController(@RequestParam int coid)
    {
        cooperationService.delete(coid);
        return Result.success("123", "成功删除！");
    }

 }
